package com.nightonke.boommenusample;

import com.nightonke.boommenu.BoomMenuButton;
import ohos.aafwk.ability.fraction.Fraction;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.Text;

import java.lang.reflect.Parameter;

public class BMBFragment extends Fraction {

    private int position;

    /**
     * on Component Attached
     * @param scatter
     * @param container
     * @param intent
     * @return
     */
    @Override
    public Component onComponentAttached(LayoutScatter scatter, ComponentContainer container, Intent intent) {
        Component fragment = scatter.parse(ResourceTable.Layout_fragment_bmb, container, false);
        Text text = (Text) fragment.findComponentById(ResourceTable.Id_text);
        text.setText(String.valueOf(position));

        BoomMenuButton bmb1 = (BoomMenuButton) fragment.findComponentById(ResourceTable.Id_bmb1);
        for (int i = 0; i < bmb1.getPiecePlaceEnum().pieceNumber(); i++)
            bmb1.addBuilder(BuilderManager.getSimpleCircleButtonBuilder());
        bmb1.buildButton();

        BoomMenuButton bmb2 = (BoomMenuButton) fragment.findComponentById(ResourceTable.Id_bmb2);
        for (int i = 0; i < bmb2.getPiecePlaceEnum().pieceNumber(); i++)
            bmb2.addBuilder(BuilderManager.getSimpleCircleButtonBuilder());
        bmb2.buildButton();
        return fragment;
    }

    /**
     * position
     * @param positions
     * @return
     */
    public BMBFragment position(int positions) {
        this.position = positions;
        return this;
    }

}
